﻿Imports System
Imports System.IO
Imports System.Configuration
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient

Module ModSeguridad
    Dim clsSeguridad As New ClsSeguridad
    Public Const C_dg_clave As String = "unab"

    Public Function busca_usuario_autenticacion(ByVal dc_usuario As String, ByRef dg_usuario As String, ByRef dg_password As String, ByRef dg_resultado As String) As Long
        busca_usuario_autenticacion = clsSeguridad.busca_usuario_autenticacion(dc_usuario, dg_usuario, dg_password, dg_resultado)
    End Function

    Public Function BuscarUsuario(ByVal dc_usuario As String, _
                              ByRef dg_usuario As String, _
                              ByRef dg_password As String, _
                              ByRef dg_mail As String, _
                              ByRef dm_vigente As String, _
                              ByRef dg_resultado As String) As Long
        BuscarUsuario = clsSeguridad.BuscarUsuario(dc_usuario, dg_usuario, dg_password, dg_mail, dm_vigente, dg_resultado)
    End Function

    Public Function ModificarUsuario(ByVal dc_usuario As String, _
                          ByVal dg_usuario As String, _
                          ByVal dg_password As String, _
                          ByVal dg_mail As String, _
                          ByVal dm_vigente As String, _
                          ByRef dg_resultado As String) As Long
        ModificarUsuario = clsSeguridad.ModificarUsuario(dc_usuario, dg_usuario, dg_password, dg_mail, dm_vigente, dg_resultado)
    End Function

    Public Function ObtieneUltimoPerfil(ByRef dc_perfil As Integer, ByRef dg_resultado As String) As Long
        ObtieneUltimoPerfil = clsSeguridad.ObtieneUltimoPerfil(dc_perfil, dg_resultado)
    End Function

    Public Function ConsultaTransacciones(ByRef grd As DataGridView, ByRef dg_resultado As String) As Long
        Dim obj_ds As DataSet = Nothing
        Dim dn_ind As Integer = 0
        Dim dn_total_registros As Integer = 0
        Dim dm_seleccion As Integer
        Dim dc_transaccion As Integer
        Dim dg_transaccion As String

        ConsultaTransacciones = clsSeguridad.ConsultaTransacciones(obj_ds, dg_resultado)
        If ConsultaTransacciones = 0 Then
            If obj_ds.Tables.Count > 0 Then
                dn_total_registros = obj_ds.Tables(0).Rows.Count - 1
                grd.Rows.Clear()
                grd.Rows.Add(dn_total_registros + 1)

                For dn_ind = 0 To dn_total_registros
                    dm_seleccion = obj_ds.Tables(0).Rows(dn_ind).Item("dm_seleccion")
                    dc_transaccion = obj_ds.Tables(0).Rows(dn_ind).Item("dc_transaccion")
                    dg_transaccion = obj_ds.Tables(0).Rows(dn_ind).Item("dg_transaccion")
                    grd.Item(0, dn_ind).Value = IIf(dm_seleccion = 0, False, True)
                    grd.Item(1, dn_ind).Value = dc_transaccion
                    grd.Item(2, dn_ind).Value = dg_transaccion
                Next dn_ind
            End If
        End If
    End Function

    Public Function busca_perfil(ByVal dc_perfil As Integer, ByRef dg_perfil As String, ByRef dm_vigente As String, ByRef dg_resultado As String) As Long
        busca_perfil = clsSeguridad.busca_perfil(dc_perfil, dg_perfil, dm_vigente, dg_resultado)
    End Function

    Public Function ConsultaTransacciones_perfil(ByVal dc_perfil As Integer, ByRef grd As DataGridView, ByRef dg_resultado As String) As Long
        Dim obj_ds As DataSet = Nothing
        Dim dn_ind As Integer = 0
        Dim dn_total_registros As Integer = 0
        Dim dc_transaccion As Integer = 0
        Dim dc_transaccion_grd As Integer = 0

        Dim dn_ind_grd As Integer = 0
        Dim dn_total_grd As Integer = 0


        ConsultaTransacciones_perfil = clsSeguridad.ConsultaTransacciones_perfil(dc_perfil, obj_ds, dg_resultado)
        If ConsultaTransacciones_perfil = 0 Then
            If obj_ds.Tables.Count > 0 Then
                dn_total_registros = obj_ds.Tables(0).Rows.Count - 1
                dn_total_grd = grd.Rows.Count - 1
                For dn_ind = 0 To dn_total_registros
                    dc_transaccion = obj_ds.Tables(0).Rows(dn_ind).Item("dc_transaccion")
                    For dn_ind_grd = 0 To dn_total_grd
                        dc_transaccion_grd = grd.Item(1, dn_ind_grd).Value
                        If dc_transaccion_grd = dc_transaccion Then
                            grd.Item(0, dn_ind_grd).Value = True
                            Exit For
                        End If
                    Next dn_ind_grd
                Next dn_ind
            End If
        End If
    End Function
    Public Function Insertar_perfil(ByVal dc_perfil As Integer, ByVal dg_perfil As String, ByVal dm_vigente As String, ByRef dg_resultado As String) As Long
        Insertar_perfil = clsSeguridad.Insertar_perfil(dc_perfil, dg_perfil, dm_vigente, dg_resultado)
    End Function

    Public Function Eliminar_perfil_transaccion(ByVal dc_perfil As Integer, ByRef dg_resultado As String) As Long
        Eliminar_perfil_transaccion = clsSeguridad.Eliminar_perfil_transaccion(dc_perfil, dg_resultado)
    End Function

    Public Function Insertar_perfil_transaccion(ByVal dc_perfil As Integer, ByVal dc_transaccion As Integer, ByRef dg_resultado As String) As Long
        Insertar_perfil_transaccion = clsSeguridad.Insertar_perfil_transaccion(dc_perfil, dc_transaccion, dg_resultado)
    End Function

    Public Function Eliminar_perfil(ByVal dc_perfil As Integer, ByRef dg_resultado As String) As Long
        Eliminar_perfil = clsSeguridad.Eliminar_perfil(dc_perfil, dg_resultado)
    End Function

    Public Function ConsultaPerfilesDisponibles(ByVal dc_usuario As String, ByRef lst As ListBox, ByRef dg_resultado As String) As Long
        Dim obj_ds As DataSet = Nothing
        Dim dn_ind As Integer = 0
        Dim dn_total_registros As Integer = 0

        ConsultaPerfilesDisponibles = clsSeguridad.ConsultaPerfilesDisponibles(dc_usuario, obj_ds, dg_resultado)

        If ConsultaPerfilesDisponibles = 0 Then
            If obj_ds.Tables.Count > 0 Then
                dn_total_registros = obj_ds.Tables(0).Rows.Count - 1
                lst.Items.Clear()
                For dn_ind = 0 To dn_total_registros
                    lst.Items.Add(obj_ds.Tables(0).Rows(dn_ind).Item("dg_perfil"))
                Next dn_ind
            End If
        End If
    End Function

    Public Function ConsultaPerfilesAsociados(ByVal dc_usuario As String, ByRef lst As ListBox, ByRef dg_resultado As String) As Long
        Dim obj_ds As DataSet = Nothing
        Dim dn_ind As Integer = 0
        Dim dn_total_registros As Integer = 0

        ConsultaPerfilesAsociados = clsSeguridad.ConsultaPerfilesAsociados(dc_usuario, obj_ds, dg_resultado)

        If ConsultaPerfilesAsociados = 0 Then
            If obj_ds.Tables.Count > 0 Then
                dn_total_registros = obj_ds.Tables(0).Rows.Count - 1
                lst.Items.Clear()
                For dn_ind = 0 To dn_total_registros
                    lst.Items.Add(obj_ds.Tables(0).Rows(dn_ind).Item("dg_perfil"))
                Next dn_ind
            End If
        End If
    End Function

    Public Function Insertar_perfil_Usuario(ByVal dc_perfil As Integer, ByVal dc_usuario As String, ByRef dg_resultado As String) As Long
        Insertar_perfil_Usuario = clsSeguridad.Insertar_perfil_Usuario(dc_perfil, dc_usuario, dg_resultado)
    End Function

    Public Function Elimina_perfil_Usuario(ByVal dc_perfil As Integer, ByVal dc_usuario As String, ByRef dg_resultado As String) As Long
        Elimina_perfil_Usuario = clsSeguridad.Elimina_perfil_Usuario(dc_perfil, dc_usuario, dg_resultado)
    End Function



End Module
